<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 后台管理系统入口
 * 
 * @author  : $Author: spike $
 * @date    : $Date: 2013-12-31 16:19:37 +0800 (二, 2013-12-31) $
 * @version : $Id: home.php 22 2013-12-31 08:19:37Z spike $
 * @rev     : $Revision: 22 $
 */
class Home extends CI_Controller 
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * [首页]
     */
    public function index()
    {
        $this->load->dao('Admin_notice_dao');
        $notice = $this->Admin_notice_dao->get(
            array('is_delete'=>UNDELETED), 
            array('notice','desc','type','create_time'),
            '`create_time` DESC',
            10
        );

        $page_style = $this->config->item('page_style');
        $data = array(
            'page_style' => $page_style['HOME'],
            'notice'     => $notice,
        );
        $this->load->view('home/header.tpl', $data);
        $this->load->view('home/index.tpl');
        $this->load->view('home/footer.tpl');
    }

    public function phpinfo()
    {
        echo phpinfo();
        die;
    }

    /**
     * [登陆]
     */
    public function login()
    {
        if($this->input->is_post_request())
        {
            $username = $this->input->post('username');
            $password = $this->input->post('password');
            $remember = $this->input->post('remember') === '1' ? TRUE : FALSE;
            
            $this->load->model('Rbac_model');
            if( TRUE === $this->Rbac_model->login($username, $password, $remember) )
            {
                redirect(DOMAIN);
            }
            else
            {
                $data = array(
                    'username' => $username,
                    'remember' => $remember,
                    'error'    => $this->Rbac_model->get_error(),
                );
                $this->load->view('home/login.tpl', $data);
            }
        }
        else
        {
            $data = array(
                'username' => $this->input->cookie('username'),
            );
            $this->load->view('home/login.tpl', $data);
        }
    }

    /**
     * [登出]
     */
    public function logout()
    {
        $this->load->model('Rbac_model');
        $this->Rbac_model->logout();
        redirect(DOMAIN);
    }
}

/* End of file home.php */